<?php

namespace App\Admin\Forms\Voter;

use App\Models\User\WxUser;
use App\Models\Voter\WxVoter;
use App\Models\Voter\WxVoterPlayer;
use App\Models\Voter\WxVoterPlayerBallot;
use App\Wen\Utils\UserUtils;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class RefusePlayerNoticeForm extends Form implements LazyRenderable
{
    use LazyWidget;

    /**
     * 处理表单请求.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $player_id = $input['id'];
        $title = $input['title'];
        $content = $input['content'];

        if(_empty_($title) || _empty_($player_id) || _empty_($content)){
            return $this->response()->error('参数错误');
        }

        $voter_player = WxVoterPlayer::find($player_id);
        if($voter_player){
            UserUtils::add_user_notice(8002, $voter_player->user_id,$title,$content,100);
            return $this->response()
                ->success('发送成功.')
                ->refresh();
        }else{
            return $this->response()->error('选手不存在');
        }
    }

    /**
     * 构建表单.
     */
    public function form()
    {
        $player_id = $this->payload["id"];
        $voter_player = WxVoterPlayer::find($player_id);
        if($voter_player){
            $voter = WxVoter::find($voter_player->voter_id);
            $this->hidden('id')->value($player_id);

            $this->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">当你想给选手发送系统通知时，可以操作这里，正常情况下，你可以直接在列表点击开关</div>';
            }, '');

            $this->text('title', '通知标题')->default('选手报名审核失败');
            $this->textarea('content', '通知内容')->help('带有代码是为了可以被点击跳转')->default('您报名"<a href="/pagesV/voter/detail/detail?id='.$voter->id.'">'.$voter->title.'</a>"选票活动审核失败，经审核，您提交的资料不合法');
        }else{
            $this->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">所对应的选票不是正常状态，无法改变其选手的状态</div>';
            }, '');
        }
    }
}
